package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.domain.AdvReservbroadcast;
import com.ruoyi.service.IAdvReservbroadcastService;
import com.ruoyi.utils.SimpleResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员预约直播清单Controller
 *
 * @author ruoyi
 * @date 2024-05-27
 */
@RestController
@RequestMapping("/system/reservbroadcast")
public class AdvReservbroadcastController extends BaseController
{
    @Autowired
    private IAdvReservbroadcastService advReservbroadcastService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:reservbroadcast:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdvReservbroadcast advReservbroadcast)
    {
        startPage();
        List<AdvReservbroadcast> list = advReservbroadcastService.selectAdvReservbroadcastList(advReservbroadcast);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @PreAuthorize("@ss.hasPermi('system:reservbroadcast:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdvReservbroadcast advReservbroadcast)
    {
        List<AdvReservbroadcast> list = advReservbroadcastService.selectAdvReservbroadcastList(advReservbroadcast);
        ExcelUtil<AdvReservbroadcast> util = new ExcelUtil<AdvReservbroadcast>(AdvReservbroadcast.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:reservbroadcast:query')")
    @GetMapping(value = "/{advReservbroadcastId}")
    public AjaxResult getInfo(@PathVariable("advReservbroadcastId") Long advReservbroadcastId)
    {
        return success(advReservbroadcastService.selectAdvReservbroadcastByAdvReservbroadcastId(advReservbroadcastId));
    }

    /**
     * 新增
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('system:reservbroadcast:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdvReservbroadcast advReservbroadcast)
    {
        return toAjax(advReservbroadcastService.insertAdvReservbroadcast(advReservbroadcast));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('system:reservbroadcast:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdvReservbroadcast advReservbroadcast)
    {
        return toAjax(advReservbroadcastService.updateAdvReservbroadcast(advReservbroadcast));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('system:reservbroadcast:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advReservbroadcastIds}")
    public AjaxResult remove(@PathVariable Long[] advReservbroadcastIds)
    {
        return toAjax(advReservbroadcastService.deleteAdvReservbroadcastByAdvReservbroadcastIds(advReservbroadcastIds));
    }

    /**
     * 判断某个会员是否已经预约了某个直播
     */
    @GetMapping("/isreservation/{advMembersId}/{advBroadcastId}")
    public SimpleResult isReservation(@PathVariable("advMembersId") String advMembersId,
            @PathVariable("advBroadcastId") String advBroadcastId) {
        boolean result = advReservbroadcastService.isReservation(advMembersId, advBroadcastId);
        return SimpleResult.success(result, "查询成功");
    }

    /**
     * 获取预约直播列表
     */
    @GetMapping("/getreservationlist/{advMembersId}")
    public TableDataInfo getReservationList(@PathVariable("advMembersId") String advMembersId) {
        startPage();
        List<AdvReservbroadcast> reservationList = advReservbroadcastService.getReservationList(advMembersId);
        return getDataTable(reservationList);
    }
}
